home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: ua302aa@lrz-muenchen.de ()
- Newsgroups: comp.lang.c
- Subject: Re: HELP! Modifying the EOF in a file!
- Date: 13 Mar 1996 06:18:12 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4i5pb4$fae@sparcserver.lrz-muenchen.de>
- References: <4i585k$4ia@news.netam.net>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- bgc@alpha.netam.net (The Bowling Green Connection) writes:
-
- >I am having trouble shortening the size of a text file...
- >Suppose I have a text file with 3 lines of data, then I
- >run this program:
-
- >void main() {
-
- Next to no comment :-)
-
- > FILE *dat;
- > dat=fopen("file.txt", "r+");
-
- I fail to see where you want to _write_ to "file.txt"
-
- > fprintf(dat, "Hello! %c", EOF);
-
- EOF cannot be a char, so printing it as a char might be a
- bad idea.
-
- > fclose(dat);
- >}
-
- Well, whatever your program does ... it is right doing so because
- it's behavior is undefined.
-
- Something as simple as
-
- #include <stdio.h>
-
- int main() {
- FILE *dat = fopen("file.txt", "w");
- if (dat) {
- fputs("Hello! ", dat);
- fclose(dat);
- }
- return 0;
- }
-
- should do what you want.
-
- >Why doesn't the EOF character chop off the remaining two lines?
-
- Since a file can be seen as a sequence of char, and since EOF is
- _not_ a char, who knows.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-